package com.sinoglobal.dumping.dumplingspring;

import android.graphics.Bitmap;
import android.widget.ImageView;

import com.sinoglobal.dumping.R;
import com.sinoglobal.dumping.adapter.Dumpling_HomeAdapter;
import com.sinoglobal.dumping.api.Dumpling_RemoteImpl;
import com.sinoglobal.dumping.base.Dumpling_SinoAsyncTask;
import com.sinoglobal.dumping.bean.Dumpling_AdvertisingBean;
import com.sinoglobal.dumping.fragment.Dumpling_HomeFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by KeZhuang on 2016/1/26.
 */
public class DumplingSpringLayout extends AbsDumplingLayout{
    private Dumpling_AdvertisingBean mListData;
    private Dumpling_HomeAdapter mAdapter;
    public DumplingSpringLayout(Dumpling_HomeFragment fragment) {
        super(fragment);
    }

    @Override
    public void operation() {
        if(mAdapter==null){
            mAdapter = new Dumpling_HomeAdapter(mFragment.getContext());
            mSupport.setAdapter(mAdapter);
        }
        mBg.setBackgroundResource(R.drawable.dumpling_chuanglian);
        mDesc.setText("特约赞助伙伴");
        mSupport.setFocusable(false);
        mFragment.showView(mSupport);

        if(mListData==null || mListData.getResultList().size()==0){
            getAdverty();
        }else{
            mAdapter.setData(mListData.getResultList());
        }
    }
    //发起请求网络广告
    public void getAdverty() {
        new Dumpling_SinoAsyncTask<Void, Void, Dumpling_AdvertisingBean>(mFragment.getContext()) {

            @Override
            public Dumpling_AdvertisingBean before(Void... params) throws Exception {
                return Dumpling_RemoteImpl.getInstance().getAdverty();
            }

            @Override
            public void after(Dumpling_AdvertisingBean dumpling_advertisingBean) {
                if (dumpling_advertisingBean != null) {
                    mListData = dumpling_advertisingBean;
                    mAdapter.setData(dumpling_advertisingBean.getResultList());
                }
            }

            @Override
            public void exception() {

            }
        }.execute();
    }
}
